package com.finger.gulimall.product.service.impl;

import org.springframework.stereotype.Service;

import java.util.Map;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.finger.common.utils.PageUtils;
import com.finger.common.utils.Query;

import com.finger.gulimall.product.dao.AttrAttrgroupRelationDao;
import com.finger.gulimall.product.entity.AttrAttrgroupRelationEntity;
import com.finger.gulimall.product.service.AttrAttrgroupRelationService;


@Service("attrAttrgroupRelationService")
public class AttrAttrgroupRelationServiceImpl extends ServiceImpl<AttrAttrgroupRelationDao, AttrAttrgroupRelationEntity> implements AttrAttrgroupRelationService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {

        // 分页查询属性和属性分组 中间表的数据
        IPage<AttrAttrgroupRelationEntity> page = this.page(
                new Query<AttrAttrgroupRelationEntity>().getPage(params),
                new QueryWrapper<AttrAttrgroupRelationEntity>()
        );

        return new PageUtils(page);
    }

    @Override
    public void updateRelationDetails(Long attrId, Long attrGroupId) {
        // 初始化属性和属性中间表的实体
        AttrAttrgroupRelationEntity entity = new AttrAttrgroupRelationEntity();
        // 设置分组id
        entity.setAttrGroupId(attrGroupId);
        // 设置属性Id
        entity.setAttrId(attrId);
        // 更新
        baseMapper.update(entity, new QueryWrapper<AttrAttrgroupRelationEntity>().eq("attr_id", attrId));
    }

}